package com.gooluke.spring.controller;

import com.gooluke.spring.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author gooluke
 * description
 * datetime 2025-04-14 23:42
 */
@Controller
@RequestMapping("/hello")
public class HelloController {

    @RequestMapping("/html")
    public String html(@RequestParam(name = "name") String name, @RequestParam(name = "age") int age, @RequestParam(name = "student") boolean isStudent) {
        return String.format("hello name: %s age: %s isStu: %s", name, age, isStudent);
    }

    @RequestMapping("/json")
    @ResponseBody
    public Map<String, Object> json(@RequestBody User user) {
        System.out.println("user.toString() = " + user.toString());
        HashMap<String, Object> map = new HashMap<>();
        map.put("userId", "huang");
        map.put("name", "黄");
        return map;
    }

    static class User {
        private String name;
        private int age;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        @Override
        public String toString() {
            return "User{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }

}
